//
//  MassRecordCell.m
//  reSearchDemo
//
//  Created by 科技 on 15/8/3.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "MassRecordCell.h"
#import "MassRecordModel.h"
#import "UIView+Layer.h"
#import "UIImageView+WebCache.h"
@interface MassRecordCell()
{
    UIImageView *headImage;
    UILabel *name;
    UILabel *time;
    UILabel *context;
}
@end

@implementation MassRecordCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        headImage = [[UIImageView alloc] init];
        [self.contentView addSubview:headImage];
        
        name = [[UILabel alloc] init];
        name.textColor = [UIColor blackColor];
        [self.contentView addSubview:name];
        
        time = [[UILabel alloc] init];
        time.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:time];
        
        context = [[UILabel alloc] init];
        context.textColor = [UIColor lightGrayColor];
        context.numberOfLines = 0;
        [self.contentView addSubview:context];
    }
    
    return self;
}

-(void)setModel:(MassRecordModel *)model {
    headImage.frame = CGRectMake(10, 10, 40, 40);
//    headImage.image = [UIImage imageNamed:model.headImage];
    [headImage sd_setImageWithUrlString:model.headImage placeholderImage:[UIImage imageNamed:@"about_icon"]];
    [UIView SetRoundedCorners:headImage andcornerRadius:CGRectGetWidth(headImage.frame)/2 andborderWidth:1.0 andborderColor:[UIColor clearColor]];
    
    name.frame = CGRectMake(CGRectGetMaxX(headImage.frame) + 5, CGRectGetMinY(headImage.frame), 200, 20);
    name.text = model.name;
    
    time.frame = CGRectMake(CGRectGetMinX(name.frame), CGRectGetMaxY(name.frame), 200, 20);
    time.text = model.time;
    
    CGSize textSize=[model.context boundingRectWithSize:CGSizeMake(self.frame.size.width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: context.font} context:nil].size;
    context.frame = CGRectMake(CGRectGetMinX(headImage.frame), CGRectGetMaxY(headImage.frame), CGRectGetWidth(self.contentView.frame) - CGRectGetMinX(headImage.frame), textSize.height);
    context.text = model.context;
    
    _height = CGRectGetMaxY(context.frame) + 10;
                            
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
